//
//  ATDetailSecondSectionTableViewCell.m
//  Adorable_Things
//
//  Created by huzhiyan on 16/1/13.
//  Copyright © 2016年 Banana Inc. All rights reserved.
//

#import "ATDetailSecondSectionTableViewCell.h"
#import "ATDetailSecondSectionCellCollectionViewCell.h"
#import "ATIntroModel.h"

@interface ATDetailSecondSectionTableViewCell () <UICollectionViewDataSource,UICollectionViewDelegate>



@end

@implementation ATDetailSecondSectionTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubCollectionViewItemSize];
    }
    return self;
}

- (void)addSubCollectionViewItemSize
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
    flowLayout.itemSize = CGSizeMake(kWidth / 4, kWidth / 4);
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kWidth / 4 + 40) collectionViewLayout:flowLayout];
    _collectionView.showsHorizontalScrollIndicator = NO;
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_collectionView];
    [self.collectionView registerNib:[UINib nibWithNibName:@"ATDetailSecondSectionCellCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ATDetailSecondSectionCellCollectionViewCell"];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _pic_urlArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ATDetailSecondSectionCellCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ATDetailSecondSectionCellCollectionViewCell" forIndexPath:indexPath];
    ATIntroModel *model = _pic_urlArray[indexPath.row];
    [cell.itemImageView sd_setImageWithURL:[NSURL URLWithString:model.pic_url]];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ATIntroModel *model = _pic_urlArray[indexPath.row];
    _block(model.item_id);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
